<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/6
 * Time: 9:41
 */
include "config.php";
if ($_SERVER["REQUEST_METHOD"]=="POST"){
    if (!empty($_REQUEST["uname"])&&!empty($_REQUEST["upwd"])){
        $loginSQL="SELECT	*FROM bangg_net.`userinfo` WHERE u_name=? AND u_pwd=?";
        $stmt=$conn->prepare($loginSQL);
        $stmt->bind_param("ss",$_REQUEST["uname"],$_REQUEST["upwd"]);
        $stmt->execute();
        $result=$stmt->get_result();
        $reslist=Array("status"=>0,"msg"=>"登录失败");
        if ($result->num_rows>=1){
            $reslist["status"]=1;
            $reslist["msg"]="登录成功";

            $user_info=$result->fetch_assoc();
            //定义一个对象重新接受用户信息
            $userinfo=Array();
            $userinfo["uid"]=$user_info["u_id"];
            $userinfo["uname"]=$user_info["u_name"];
            $userinfo["utel"]=$user_info["u_tel"];
            $reslist["userinfo"]=$userinfo;
//            print_r(json_encode($user_info));
            print_r(json_encode($reslist));
        }else{
            print_r(json_encode(Array("status"=>0,"msg"=>"用户名或密码错误")));
        }
    }else{
        print_r(json_encode(Array("status"=>0,"msg"=>"参数错误")));
    }
}else{
    print_r(json_encode(Array("status"=>0,"msg"=>"请使用post请求")));
}